package com.jdk8datedemo;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;

public class LocalDateDemo {
    public static void main(String[] args) {

        //1.获取当前时间的日历对象(包含年月日)
        LocalDate now = LocalDate.now();
        System.out.println(now);

        //2.获取指定的时间的日历对象
        LocalDate localDate = LocalDate.of(2023, 10, 1);
        System.out.println(localDate);

        //3.get系列方法获取日历中的每一个属性值
        //获取年
        int year = localDate.getYear();
        System.out.println(year);

        //获取月
        Month month = localDate.getMonth();
        System.out.println(month);
        System.out.println(month.getValue());
        int monthValue = localDate.getMonthValue();
        System.out.println(monthValue);

        //获取日
        int dayOfMonth = localDate.getDayOfMonth();
        System.out.println(dayOfMonth);
        int dayOfYear = localDate.getDayOfYear();
        System.out.println(dayOfYear);

        //获取星期
        DayOfWeek dayOfWeek = localDate.getDayOfWeek();
        System.out.println(dayOfWeek);
        System.out.println(dayOfWeek.getValue());

        //is开头的方法表示判断
        System.out.println(localDate.isAfter(now));
        System.out.println(localDate.isBefore(now));

        //with开头的方法表示修改,只能修改年月日
        LocalDate localDate1 = localDate.withYear(2000);
        System.out.println(localDate1);

        //minus开头的方法表示减少,只能减少年月日
        LocalDate localDate2 = localDate.minusYears(1);
        System.out.println(localDate2);

        //plus开头的方法表示增加,只能增加年月日
        LocalDate localDate3 = localDate.plusYears(1);
        System.out.println(localDate3);

        //判断今天是否是你的生日
        LocalDate birDate = LocalDate.of(2000, 1, 1);
        LocalDate nowDate = LocalDate.now();

        MonthDay birMD = MonthDay.of(birDate.getMonth(), birDate.getDayOfMonth());
        MonthDay monthDay = MonthDay.from(nowDate);

        System.out.println(monthDay.equals(birMD));
    }
}
